import CryptoJS from "crypto-js";

// Guid
export function GenRandomString() {
  return "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, function(c) {
    const r = (Math.random() * 16) | 0,
      v = c == "x" ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });
}

export function Guid() {
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
    var r = (Math.random() * 16) | 0,
      v = c == "x" ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });
}

// 加密
export function Encrypt(text, auth) {
  const a = CryptoJS.enc.Latin1.parse(auth);
  const b = CryptoJS.enc.Latin1.parse(auth.substring(10, 26));
  const encoded = CryptoJS.AES.encrypt(text, a, {
    iv: b,
    mode: CryptoJS.mode.CBC,
    adding: CryptoJS.pad.ZeroPadding
  }).toString();
  return encoded;
}
